package demo6;

public class Singleton {
    //1：私有化构造器，避免外面随意创建对象
    private Singleton() {
    }

    //2:创建一个私有的静态变量，用来保存唯一实例
    private static Singleton instance = new Singleton();

    //3:定义一个静态方法。返回唯一实例
    public static Singleton getInstance() {
        return instance;
    }
}
